package chances.system.operator.web;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.springframework.security.core.Authentication;
import org.springframework.security.core.context.SecurityContextHolder;
import org.springframework.web.servlet.handler.HandlerInterceptorAdapter;


public class OperatorSessionInterceptor extends HandlerInterceptorAdapter {
	
	@Override
	public boolean preHandle(HttpServletRequest request, HttpServletResponse response, Object handler)
			throws Exception {
		Authentication authentication = SecurityContextHolder.getContext().getAuthentication();
		if(authentication != null){
			Object principal = authentication.getPrincipal();
			if(principal != null){
				request.setAttribute(OperatorSession.SESSION_NAME, principal);
			}
		}
		request.setAttribute("accessPath", request.getRequestURI());
		return super.preHandle(request, response, handler);
	}
}